package edu.nf.db.util.result;

import edu.nf.db.util.RowProcessor;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author lzp
 * @Date 2024-05-10
 */
public class ColumnListHandler<T> extends AbstractListHandler<T>{

    private Integer index;
    private String columnName;

    public ColumnListHandler(Integer index) {
        this.index = index;
    }

    public ColumnListHandler(String columnName) {
        this.columnName = columnName;
    }

    @SuppressWarnings("unchecked")
    @Override
    public T handlerRow(ResultSet rs) throws SQLException {
        if (this.columnName == null){
            return (T) RowProcessor.toValue(rs,index);
        }
        return (T) RowProcessor.toValue(rs,columnName);
    }
}
